<?php

namespace app\api\controller;

use app\common\controller\ApiBasic;
use app\common\service\crm\BusinessService;
use app\common\service\crm\ContactsService;
use app\common\service\hrm\CompanyService;
use app\common\service\hrm\DeptService;
use app\common\service\hrm\RankingService;
use app\common\service\sys\DictService;
use app\common\service\sys\UserGroupService;
use app\common\service\sys\UserService;
use app\common\service\xzm\CarService;
use app\common\service\sys\UserGroupMemberService;
use app\common\service\pmm\AuditGroupService;
use app\common\service\crm\CustomerService;
use app\common\service\pmm\ConfigService;
use app\common\service\wms\CategoryService;
use app\common\service\wms\ProductService;
use app\common\service\wms\WarehouseService;

/**
 * 弹出选择窗集聚在此控制器
 * @author kaige
 * @update 2022-11-03
 */
class Select extends ApiBasic
{

    //选择单位
    public function company()
    {
        if ($this->request->isGet()) {
            return json((new CompanyService())->_list(input('param.')));
        }
        return _jerr(1000);
    }

     //选择单位树型
     public function companytree()
     {
         if ($this->request->isGet()) {
            return _jok('',(new CompanyService())->companyTree());
         }
         return _jerr(1000);
     }

    //获取流程配置--单模块
    public function flowconfig()
    {
        if ($this->request->isGet()) {
            $modu_id = input('modu_id/d', 0);
            $outlist = (new ConfigService())->getInfoById($modu_id);
            //手动模式，删除表单配置
            if ($outlist['form_type'] == 2) {
                unset($outlist['form_json']);
            }
            return json($outlist);
        }
        return _jerr(1000);
    }

    //选择员工
    public function employee()
    {
        if ($this->request->isGet()) {
            return json((new UserService())->_list(input('param.')));
        }
        return _jerr(1000);
    }

    //选择职位
    public function ranking()
    {
        if ($this->request->isGet()) {
            return (new RankingService())->_list(input('param.'));
        }
        return _jerr(1000);
    }
    //选择职位树型
    public function rankingtree()
    {
        if ($this->request->isGet()) {
            return _jok('',(new RankingService())->rankingTree());
        }
        return _jerr(1000);
    }

    //选择部门
    public function dept()
    {
        if ($this->request->isGet()) {
            return (new DeptService())->_list(input('param.'), false);
        }
        return _jerr(1000);
    }

    //选择部门树型
    public function depttree()
    {
        if ($this->request->isGet()) {
            return _jok('',(new DeptService())->deptTree());
        }
        return _jerr(1000);
    }

    //选择字典
    public function dict()
    {
        if ($this->request->isGet()) {
            return json((new DictService())->_list(input('param.'), false));
        }
        return _jerr(1000);
    }

    // 选择用户分组
    public function usergroup()
    {
        if ($this->request->isGet()) {
            return json((new UserGroupService())->_list(input('param.'), false));
        }
        return _jerr(1000);
    }

    // 选择用户分组
    public function usergroupdept()
    {
        if ($this->request->isGet()) {
            return json([
                'group' => (new UserGroupService())->getUserGroupLayuiTree(),
                'dept' => (new DeptService())->getDeptLayuiTree()
            ]);
        }
        return _jerr(1000);
    }

    // 选择分组用户
    public function usergrouplist()
    {
        if ($this->request->isGet()) {
            $group_id = input('group_id/d', 0);
            return json((new UserGroupMemberService())->getUserByGroup($group_id));
        }
        return _jerr(1000);
    }

    // 选择用户
    public function ugdcuserlist()
    {
        if ($this->request->isGet()) {
            $ids = input('ids', '');
            return json((new UserService())->getugdcUserList($ids));
        }
        return _jerr(1000);
    }


    //选择车牌号
    public function licenseplatenumber()
    {
        if ($this->request->isGet()) {
            return json((new CarService())->_list(input('param.')));
        }
        return _jerr(1000);
    }

    //审核人员分组
    public function auditgroup()
    {
        if ($this->request->isGet()) {
            return (new AuditGroupService())->getauditgroup();
        }
        return _jerr(1000);
    }

    /**
     * 客户
     */
    public function customer()
    {
        if ($this->request->isGet()) {
            $data = input('param.');
            return json((new CustomerService())->_list($data));
        }
        return _jerr(1000);
    }

    /**
     * 产品类型
     */
    public function category()
    {
        if ($this->request->isGet()) {
            $data = input('param.');
            return json((new CategoryService())->_list($data));
        }
        return _jerr(1000);
    }

    /**
     * 产品类型树
     */
    public function categorytree()
    {
        if ($this->request->isGet()) {
            return _jok('',(new CategoryService())->categoryTree());
        }
        return _jerr(1000);
    }

    /**
     * 仓库区树
     */
    public function warehousetree()
    {
        if ($this->request->isGet()) {
            return _jok('',(new WarehouseService())->warehousetree());
        }
        return _jerr(1000);
    }

    /**
     * 产品
     */
    public function productlist()
    {
        if ($this->request->isGet()) {
            $data = input('param.');
            return json((new ProductService())->_list($data));
        }
        return _jerr(1000);
    }

    /**
     * 商机
     */
    public function business()
    {
        if ($this->request->isGet()) {
            $data = input('param.');
            return json((new BusinessService())->_list($data));
        }
        return _jerr(1000);
    }

    /**
     * 客户联系人
     */
    public function contacts()
    {
        if ($this->request->isGet()) {
            $data = input('param.');
            return json((new ContactsService())->_list($data));
        }
        return _jerr(1000);
    }

}